<template>
  <el-dialog
    :title="!dataForm.oid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="科室" prop="odepartment">
      <el-input v-model="dataForm.odepartment" placeholder="科室"></el-input>
    </el-form-item>
    <el-form-item label="诊断结果" prop="oresult">
      <el-input v-model="dataForm.oresult" placeholder="检测结果"></el-input>
    </el-form-item>
    <el-form-item label="诊断医师" prop="odname">
      <el-input v-model="dataForm.odname" placeholder="诊断医师"></el-input>
    </el-form-item>
    <el-form-item label="开始时间" prop="ostime">
      <!-- 修改 -->
      <el-date-picker v-model="dataForm.ostime" placeholder="开始时间"  type="datetime"></el-date-picker>
    </el-form-item>
    <el-form-item label="结束时间" prop="oetime" >
      <!-- 修改 -->
      <el-date-picker v-model="dataForm.oetime" placeholder="结束时间" type="date"></el-date-picker>
    </el-form-item>
    <el-form-item label="诊断建议" prop="omessage">
      <el-input v-model="dataForm.omessage" placeholder="建议"></el-input>
    </el-form-item>
    <el-form-item label="患者" prop="opatientname">
      <el-input v-model="dataForm.opatientname" placeholder="患者"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          oid: 0,
          odepartment: '',
          oetime: '',
          ostime: '',
          opatientname: '',
          odname: '',
          oresult: '',
          omessage: ''
          
        },
        dataRule: {
          odepartment: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          ostime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          oetime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          opatientname: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          odname: [
            { required: false, message: '不能为空', trigger: 'blur' }
          ],
          omessage: [
            { required: false, message: '不能为空', trigger: 'blur' }
          ],
          oresult: [
            { required: false, message: '不能为空', trigger: 'blur' }
          ],
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.oid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.oid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/order/info/${this.dataForm.oid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.odepartment = data.order.odepartment
                this.dataForm.ostime = data.order.ostime
                console.log(typeof(data.order.ostime))
                this.dataForm.oetime = data.order.oetime
                this.dataForm.opatientname = data.order.opatientname
                this.dataForm.odname = data.order.odname
                this.dataForm.omessage = data.order.omessage
                this.dataForm.oresult =data.order.oresult
               
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/order/${!this.dataForm.oid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'oid': this.dataForm.oid || undefined,
                'odepartment': this.dataForm.odepartment,
                'ostime': this.dataForm.ostime,
                'oetime': this.dataForm.oetime,
                'opatientname': this.dataForm.opatientname,
                'odname': this.dataForm.odname,
                'omessage': this.dataForm.omessage,
                'oresult': this.dataForm.oresult
                
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
